#!/usr/bin/env sh

log_path=/tmp/.gammastep.log
sunset_path=~/.config/scripts/setSunset.sh
defalut_temperature=6500

temperature=$(cat $log_path | grep 'Color temperature:' | tail -n 1 | grep -o '[0-9]\+')
if [[ -z $temperature ]]
then
  temperature=$defalut_temperature
fi

killall gammastep

if [[ $1 = "0" ]]
then
  $sunset_path > $log_path 2>&1 &
else
  temperature=$(( $temperature $1 ))
  gammastep -O $temperature -vr > $log_path 2>&1 &
fi
  
